package com.lijing.mock.config;

import com.lijing.mock.web.filter.ApiFilter;
import org.springframework.boot.web.servlet.FilterRegistrationBean;
import org.springframework.context.annotation.Bean;
import org.springframework.web.filter.CharacterEncodingFilter;

import javax.servlet.Filter;

/**
 * 过滤器加载配置
 * @author by lijing
 * @date 2019/12/2 0002 14:43
 */
public class WebFilterConfig {
    @Bean
    public Filter characterEncodingFilter() {
        CharacterEncodingFilter c = new CharacterEncodingFilter();
        c.setEncoding("UTF-8");
        return c;
    }

    @Bean
    public FilterRegistrationBean dispatchFilterRegister() {
        FilterRegistrationBean registrationBean = new FilterRegistrationBean();
        registrationBean.setFilter(dispatch());
        registrationBean.addUrlPatterns("/dispatch/*");
        registrationBean.setName("dispatch");
        registrationBean.setOrder(1);
        return registrationBean;
    }

    @Bean
    public Filter dispatch() {
        return new ApiFilter();
    }

}
